$(function(){
    userList();
    usersearch();
    //todo 编辑
    $('.update').click(function(){
        let id = $(this).attr('ids');
        let urls = "../user/edit.html?id="+id;
        layOpen('编辑用户信息','90%','600px',urls)
    });

    //todo 删除
    $('.del').click(function(){
        let id = $(this).attr('ids');
        let data = {'admin_id':id};
        let urls = url+'admin/adminDel';
        layFirm('删除',urls,data);
    });

    //todo 详情
    $('.detail').click(function(){
        let id = $(this).attr('ids');
        let urls = './detail.html?uid='+id;
        layOpen('用户详情','50%','600px',urls);
    })

});

function usersearch() {
    $('#search').click(function(){
        userList();
    })
}
function userList(){
    let nickname = $('input[name="nickname"]').val();
    let phone    = $('input[name="phone"]').val();
    let page = GetQueryString('page');
    if(!page || page <=0)page = 1;
    let ref = {
        nickname:nickname,
        page:page,
        limit:limit,
        phone:phone,
    };
    page = parseInt(page);
    let res = AjaxForm('admin/userList','get',ref);
    let data = res.list;
    let html ='';
    let pageHtml = '';
    if(res.count < 1){
        lay('没有更多数据了');
        html = `<tr></tr>`;
    }else{
        for (let i=0;i<=data.length-1;i++){
            let rt = '手机';
            if(data[i].rt === 2)rt = '微信';
            html +=
                "<tr class=\"table-content\" style='height: 50px;'>\n" +
                "<td style=\" line-height: 50px;height: 50px;width: 7%\">"+data[i].nickname+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 10%\">"+data[i].phone+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 7%\"><img style='height: 45px' src='"+data[i].headimg+"'></td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 5%\">"+data[i].integral+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 5%\">"+rt+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 15%\">"+formatDateTime(data[i].log_time)+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 15%\">"+formatDateTime(data[i].create_time)+"</td>" +
                "<td style=\" line-height: 50px;height: 50px;width: 10%\">"+
                // "<!--<a class=\"layui-btn layui-btn-mini\" lay-event=\"detail\">查看</a>-->\n" +
                // "<a class=\"update layui-btn layui-btn-mini layui-btn-normal\" ids='"+data[i].uid+"'>编辑</a>" +
                "<a class=\"detail layui-btn layui-btn-mini layui-btn-danger\" ids='"+data[i].uid+"'>详情</a>" +
                "</td>\n" +
                "</tr>"
        }
        //todo 分页
        pageHtml = WepPage(data.count,page,limit,"list");
    }
    html += pageHtml;
    $('#data-table').html(html);
}



